home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 43
/
Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso
/
Aminet
/
comm
/
tcp
/
Amster-source.lha
/
Amster_Install
/
Source
/
resultview.c
< prev
next >
Wrap
C/C++ Source or Header
|
2001-03-14
|
19KB
|
670 lines
/*
** Amster - Result View
** Copyright © 1999-2000 by Gürer Özen
** Copyright © 2000-2001 by Jacob Laursen
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "amster.h"
#include <proto/dos.h>
#include <MUI/Lamp_mcc.h>
#include <MUI/NListview_mcc.h>
#include "amster_Cat.h"
/* Private prototypes */
ULONG resultview_new(struct IClass *cl, Object *obj, struct opSet *msg);
Object *ResultviewContextMenuBuild(struct IClass *cl, Object *obj, struct MUIP_NList_ContextMenuBuild *msg);
MUI_LIST_DISP_DECL(resultlistdisp, song s);
MUI_NLIST_COMP_DECL(resultlistcomp);
void resultview_clear(struct resultdata *data, int t);
void resultview_download(struct resultdata *data, int t, int num);
void resultview_nick(struct resultdata *data, char *nick);
void resultview_stat(struct resultdata *data, int t);
void resultview_found(struct resultdata *data, song s);
void resultview_reset(struct resultdata *data);
void resultview_fillstem(struct resultdata *data, char *stem);
struct MUI_CustomClass *ResultviewContext;
/* Global variables */
char *gColFormat;
int gContextChoice;
MUI_DISPATCH(resultview_dispatch)
{
struct resultdata *data;
switch (msg->MethodID) {
case OM_NEW:
return(resultview_new(cl, obj, (APTR)msg));
case RESULTVIEW_CLEAR:
data = INST_DATA(cl, obj);
resultview_clear(data, (int)(((muimsg)msg)->arg1));
return NULL;
case RESULTVIEW_DOWNLOAD:
data = INST_DATA(cl, obj);
resultview_download(data, (int)(((muimsg)msg)->arg1), (int)(((muimsg)msg)->arg2));
return NULL;
case RESULTVIEW_FOUND:
data = INST_DATA(cl, obj);
resultview_found(data, (song)(((muimsg)msg)->arg1));
return NULL;
case RESULTVIEW_TOGGLE_BOTH:
{
u_long tmp;
data = INST_DATA(cl, obj);
GetAttr(MUIA_Selected, data->fptog, &tmp);
prf->fullpath = tmp;
DoMethod(gui->searchpanel, SEARCH_TOGGLE);
DoMethod(gui->WI_Hotlist, HOTLIST_TOGGLE);
return NULL;
}
case RESULTVIEW_TOGGLE_ONE:
data = INST_DATA(cl, obj);
set(data->fptog, MUIA_Selected, prf->fullpath);
DoMethod(data->list, MUIM_NList_Redraw, MUIV_NList_Redraw_All);
return NULL;
case RESULTVIEW_STAT:
data = INST_DATA(cl, obj);
set(data->result, MUIA_Text_Contents, (char *)(((muimsg)msg)->arg1));
return NULL;
case RESULTVIEW_STAT2:
data = INST_DATA(cl, obj);
resultview_stat(data, (int)(((muimsg)msg)->arg1));
return NULL;
case RESULTVIEW_INSERT:
data = INST_DATA(cl, obj);
DoMethod(data->list, MUIM_NList_InsertSingle, (song)(((muimsg)msg)->arg1), MUIV_NList_Insert_Sorted);
return NULL;
case RESULTVIEW_NICK:
{
data = INST_DATA(cl, obj);
resultview_nick(data, (char *)(((muimsg)msg)->arg1));
return NULL;
}
case RESULTVIEW_RESETCOUNT:
data = INST_DATA(cl, obj);
data->resultview_count = 0;
return NULL;
case RESULTVIEW_GETSTATE:
data = INST_DATA(cl, obj);
search_state = data->resultview_state;
return NULL;
case RESULTVIEW_FILLSTEM:
data = INST_DATA(cl, obj);
resultview_fillstem(data, (char *)(((muimsg)msg)->arg1));
return NULL;
case RESULTVIEW_ADDTOHOTLIST:
{
song item;
data = INST_DATA(cl, obj);
DoMethod(data->list, MUIM_NList_GetEntry, gContextChoice, &item);
if (item) {
DoMethod(gui->WI_Hotlist, HOTLIST_ADD, item->user);
}
return NULL;
}
case RESULTVIEW_NICKFROMLIST:
{
song item;
data = INST_DATA(cl, obj);
DoMethod(data->list, MUIM_NList_GetEntry, gContextChoice, &item);
if (item) {
DoMethod(gui->searchpanel, SEARCH_NICK, item->user);
}
return NULL;
}
}
return(DoSuperMethodA(cl, obj, msg));
}
ULONG resultview_new(struct IClass *cl, Object *obj, struct opSet *msg)
{
static struct Hook resultlistdispHook = { {0,0}, &resultlistdisp, NULL, NULL };
static struct Hook resultlistcompHook = { {0,0}, &resultlistcomp, NULL, NULL };
struct resultdata *data;
Object *result, *list;
Object *BT_Clear, *BT_ClearAll, *BT_Download, *fptog;
/* Object *BT_Resume;*/
/* Determine wether to use a context menu or not! */
if (GetTagData(MUIA_Amster_ContextMenu, FALSE, msg->ops_AttrList)) list = NewObject(ResultviewContext->mcc_Class, NULL,
InputListFrame,
MUIA_NList_Title, TRUE,
MUIA_NList_Format, gColFormat,
MUIA_NList_MinColSortable, 0,
MUIA_NList_MultiSelect, MUIV_NList_MultiSelect_Default,
MUIA_NList_DisplayHook, &resultlistdispHook,
MUIA_NList_CompareHook2, &resultlistcompHook,
MUIA_CycleChain, 1);
else list = NListObject,
InputListFrame,
MUIA_NList_Title, TRUE,
MUIA_NList_Format, gColFormat,
MUIA_NList_MinColSortable, 0,
MUIA_NList_MultiSelect, MUIV_NList_MultiSelect_Default,
MUIA_NList_DisplayHook, &resultlistdispHook,
MUIA_NList_CompareHook2, &resultlistcompHook,
MUIA_CycleChain, 1);
if (obj = (Object *)DoSuperNew(cl, obj,
Child, VGroup,
Child, HGroup,
Child, Label(MSG_RESULT),
Child, result = TextObject, End,
End,
Child, NListviewObject,
MUIA_NListview_NList, list,
/*
MUIA_NListview_NList, list = NewObject(ResultviewContext->mcc_Class, NULL,
InputListFrame,
MUIA_NList_Title, TRUE,
MUIA_NList_Format, gColFormat,
MUIA_NList_MultiSelect, MUIV_NList_MultiSelect_Default,
MUIA_NList_DisplayHook, &resultlistdispHook,
MUIA_NList_CompareHook2, &resultlistcompHook,
MUIA_CycleChain, 1,
End,
*/
End,
Child, HGroup,
Child, BT_Clear = SimpleButton(MSG_CLEAR_GAD),
Child, BT_ClearAll = SimpleButton(MSG_CLEARALL_GAD),
/* Child, BT_Resume = SimpleButton(MSG_RESUME_GAD),*/
Child, BT_Download = SimpleButton(MSG_DOWNLOAD_GAD),
Child, TextObject,
MUIA_HorizWeight, 25,
MUIA_Text_PreParse, "\33r",
MUIA_Text_Contents, MSG_SEARCH_FULLPATH,
End,
Child, fptog = ImageObject,
ButtonFrame,
MUIA_HorizWeight, 10,
MUIA_Background, MUII_ButtonBack,
MUIA_InputMode, MUIV_InputMode_Toggle,
MUIA_ShowSelState, FALSE,
MUIA_Image_Spec, "6:15",
MUIA_Selected, prf->fullpath,
End,
End,
End,
TAG_MORE, msg->ops_AttrList))
{
data = INST_DATA(cl, obj);
data->result = result;
data->list = list;
/* data->BT_Resume = BT_Resume;*/
data->BT_Clear = BT_Clear;
data->BT_ClearAll = BT_ClearAll;
data->BT_Download = BT_Download;
data->fptog = fptog;
lamp_useinlist(list);
DoMethod(BT_Clear, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, RESULTVIEW_CLEAR, CLEAR_MARKED);
DoMethod(BT_ClearAll, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, RESULTVIEW_CLEAR, CLEAR_ALL );
DoMethod(BT_Download, MUIM_Notify, MUIA_Pressed, FALSE, obj, 3, RESULTVIEW_DOWNLOAD, 0, 0);
/* DoMethod(BT_Resume, MUIM_Notify, MUIA_Pressed, FALSE, obj, 3, RESULTVIEW_DOWNLOAD, 2, 0);*/
DoMethod(list, MUIM_Notify, MUIA_NList_DoubleClick, MUIV_EveryTime, obj, 3, RESULTVIEW_DOWNLOAD, 1, 0);
DoMethod(fptog, MUIM_Notify, MUIA_Selected, MUIV_EveryTime, obj, 1, RESULTVIEW_TOGGLE_BOTH);
DoMethod(list, MUIM_Notify, MUIA_NList_TitleClick, MUIV_EveryTime, list, 4, MUIM_NList_Sort3, MUIV_TriggerValue, MUIV_NList_SortTypeAdd_2Values, MUIV_NList_Sort3_SortType_Both);
DoMethod(list, MUIM_Notify, MUIA_NList_TitleClick2, MUIV_EveryTime, list, 4, MUIM_NList_Sort3, MUIV_TriggerValue, MUIV_NList_SortTypeAdd_2Values, MUIV_NList_Sort3_SortType_2);
DoMethod(list, MUIM_Notify, MUIA_NList_SortType, MUIV_EveryTime, list, 3, MUIM_Set, MUIA_NList_TitleMark, MUIV_TriggerValue);
DoMethod(list, MUIM_Notify, MUIA_NList_SortType2, MUIV_EveryTime, list, 3, MUIM_Set, MUIA_NList_TitleMark2, MUIV_TriggerValue);
return((ULONG)obj);
}
return NULL;
}
MUI_DISPATCH(ResultviewContextDispatcher)
{
switch (msg->MethodID)
{
case MUIM_NList_ContextMenuBuild:
return (ULONG) ResultviewContextMenuBuild(cl, obj, (struct MUIP_NList_ContextMenuBuild *)msg);
break;
case MUIM_ContextMenuChoice:
{
int item = muiUserData(((struct MUIP_ContextMenuChoice *)msg)->item);
switch (item) {
case 0:
DoMethod(gui->searchpanel, SEARCH_ADDTOHOTLIST);
break;
case 1:
DoMethod(gui->searchpanel, SEARCH_NICKFROMLIST);
break;
}
return NULL;
}
}
return(DoSuperMethodA(cl, obj, msg));
}
Object *ResultviewContextMenuBuild(struct IClass *cl, Object *obj, struct MUIP_NList_ContextMenuBuild *msg)
{
struct ResultviewContextData *data = INST_DATA(cl, obj);
if (msg->ontop || msg->pos == -1) {
return NULL; /* Default context menu when pointer isn't on an entry */
}
else {
gContextChoice = msg->pos;
return (
MenustripObject,
Child, MenuObject,
MUIA_Menu_Title, MSG_MAINCONTEXTMENU_TITLE,
Child, data->MI_AddToHotlist = MenuitemObject,
MUIA_Menuitem_Title, MSG_MAINCONTEXTMENU_ADD,
MUIA_UserData, 0,
End,
Child, data->MI_BrowseUser = MenuitemObject,
MUIA_Menuitem_Title, MSG_MAINCONTEXTMENU_BROWSE,
MUIA_UserData, 1,
End,
End,
End);
}
}
MUI_LIST_DISP(resultlistdisp, song s)
{
static char buf[50], buf2[50], buf3[50], time[40];
if (s) {
if (s->link == 0)
*array++ = lamp_getforlist(0);
else if(s->link < 5)
*array++ = lamp_getforlist(1);
else if(s->link < 8)
*array++ = lamp_getforlist(2);
else
*array++ = lamp_getforlist(3);
if (prf->fullpath)
*array++ = s->title;
else
*array++ = nap_strippath(s->title);
sprintf(buf,"\33c%d",s->bit);
*array++ = buf;
sprintf(buf2,"\33c%d",s->freq);
*array++ = buf2;
sprintf(buf3,"\33r%ld",s->size);
*array++ = buf3;
if (s->time>0) {
int secs = s->size/(s->bit*125);
if (abs(s->time - secs)*100/s->time > 3)
sprintf(time, "\33r\33i%ld:%02ld", s->time/60, s->time%60);
else
sprintf(time, "\33r%ld:%02ld", s->time/60, s->time%60);
}
else {
sprintf(time,"\33r0:00");
}
*array++ = time;
*array++ = s->user;
*array = nap_linktype[s->link];
}
else {
*array++ = "\33c@";
*array++ = (char *)MSG_LH_SONG;
*array++ = (char *)MSG_LH_KBPS;
*array++ = (char *)MSG_LH_HZ;
*array++ = (char *)MSG_LH_SIZE;
*array++ = (char *)MSG_LH_TIME;
*array++ = (char *)MSG_LH_USER;
*array = (char *)MSG_LH_LINK;
}
return(0);
}
void resultview_clear(struct resultdata *data, int t)
{
u_long item;
switch(t) {
case CLEAR_MARKED:
{
u_long listid = MUIV_NList_NextSelected_Start;
for (;;) {
DoMethod(data->list, MUIM_NList_NextSelected, &listid);
if (listid==MUIV_NList_NextSelected_End) break;
DoMethod(data->list, MUIM_NList_GetEntry,listid, &item);
if (item) {
DoMethod(data->list, MUIM_NList_Remove, MUIV_NList_Remove_Selected);
nap_songfree((song)item);
}
}
break;
}
case CLEAR_ALL:
set(data->list,MUIA_NList_Quiet, MUIV_NList_Quiet_Visual);
while (1) {
DoMethod(data->list, MUIM_NList_GetEntry, 0, &item);
if(!item) break;
DoMethod(data->list, MUIM_NList_Remove, MUIV_NList_Remove_First);
nap_songfree((song)item);
}
set(data->list,MUIA_NList_Quiet, MUIV_NList_Quiet_None);
resultview_stat(data, 0);
break;
}
}
void resultview_download(struct resultdata *data, int t, int num)
{
int f=0;
u_long item, listid;
if (gui_onlinestate < ONLINE) {
gRC = 10;
return;
}
switch (t) {
case 0:
listid = MUIV_NList_NextSelected_Start;
for (;;) {
DoMethod(data->list, MUIM_NList_NextSelected, &listid);
if (listid == MUIV_NList_NextSelected_End) break;
DoMethod(data->list, MUIM_NList_GetEntry, listid, &item);
if (item) {
if (!f) {
DoMethod(gui->iconpanel, PANEL_OPENDL);
f=1;
}
dl_addq((song)item);
}
}
break;
case 1:
GetAttr(MUIA_NList_DoubleClick, data->list, &listid);
if (listid == -1 || listid == -2) return;
DoMethod(data->list, MUIM_NList_GetEntry, listid, &item);
if (!item) return;
if (!f) {
DoMethod(gui->iconpanel, PANEL_OPENDL);
f=1;
}
dl_addq((song)item);
break;
case 2:
DoMethod(data->list, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active, &item);
if (!item) return;
#ifdef AMSTER_DEBUG
gui_debugf("Resume attempted for: %s", ((song)item)->title);
#endif
break;
case 3:
DoMethod(data->list, MUIM_NList_GetEntry, num, &item);
if (item) {
if (!f) {
f=1;
}
dl_addq((song)item);
}
else gRC = 9;
break;
}
}
void resultview_nick(struct resultdata *data, char *nick)
{
if (gui_onlinestate < ONLINE) return;
data->resultview_count = 0;
if (prf->clrlist) resultview_clear(data, CLEAR_ALL);
nap_sendbuf(NAPC_BROWSEUSER, nick);
resultview_stat(data, 3);
}
void resultview_stat(struct resultdata *data, int t)
{
static char buf[80];
char *txt;
switch(t) {
case 0:
txt = "";
data->resultview_state = 0;
break;
case 1:
data->resultview_state = 1;
txt = (char *)MSG_STATUS1_SEARCHING;
break;
case 2:
if (data->resultview_count == 0)
txt = (char*)MSG_STATUS1_NOFILES;
else if (data->resultview_count == 1)
txt = (char*)MSG_STATUS1_ONEFOUND;
else {
sprintf(buf, MSG_STATUS1_FOUND, data->resultview_count);
txt = buf;
}
data->resultview_state = 2;
break;
case 3:
txt = (char *)MSG_STATUS1_REQLIST;
break;
}
set(data->result, MUIA_Text_Contents, txt);
}
void resultview_found(struct resultdata *data, song s)
{
if (s) {
DoMethod(data->list, MUIM_NList_InsertSingle, s, MUIV_NList_Insert_Sorted);
data->resultview_count++;
}
else {
resultview_stat(data, 2);
}
}
MUI_NLIST_COMP(resultlistcomp)
{
song entry1 = ncm->entry1;
song entry2 = ncm->entry2;
LONG col1 = ncm->sort_type & MUIV_NList_TitleMark_ColMask;
LONG col2 = ncm->sort_type2 & MUIV_NList_TitleMark2_ColMask;
ULONG result = 0;
if (ncm->sort_type == MUIV_NList_SortType_None) return (0);
if (col1 == 1) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) {
if (prf->fullpath) result = (LONG) stricmp(entry2->title, entry1->title);
else result = (LONG) stricmp(nap_strippath(entry2->title), nap_strippath(entry1->title));
}
else {
if (prf->fullpath) result = (LONG) stricmp(entry1->title, entry2->title);
else result = (LONG) stricmp(nap_strippath(entry1->title), nap_strippath(entry2->title));
}
}
else if (col1 == 2) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = entry2->bit - entry1->bit;
else
result = entry1->bit - entry2->bit;
}
else if (col1 == 3) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = entry2->freq - entry1->freq;
else
result = entry1->freq - entry2->freq;
}
else if (col1 == 4) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = entry2->size - entry1->size;
else
result = entry1->size - entry2->size;
}
else if (col1 == 5) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = entry2->time - entry1->time;
else
result = entry1->time - entry2->time;
}
else if (col1 == 6) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = (LONG) stricmp(entry2->user, entry1->user);
else
result = (LONG) stricmp(entry1->user, entry2->user);
}
else if (col1 == 7) {
if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask)
result = entry2->link - entry1->link;
else
result = entry1->link - entry2->link;
}
if ((result != 0) || (col1 == col2)) return (result);
if (col2 == 1) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) {
if (prf->fullpath) result = (LONG) stricmp(entry2->title, entry1->title);
else result = (LONG) stricmp(nap_strippath(entry2->title), nap_strippath(entry1->title));
}
else {
if (prf->fullpath) result = (LONG) stricmp(entry1->title, entry2->title);
else result = (LONG) stricmp(nap_strippath(entry1->title), nap_strippath(entry2->title));
}
}
else if (col2 == 2) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask)
result = entry2->bit - entry1->bit;
else
result = entry1->bit - entry2->bit;
}
else if (col2 == 3) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask)
result = entry2->freq - entry1->freq;
else
result = entry1->freq - entry2->freq;
}
else if (col2 == 4) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask)
result = entry2->size - entry1->size;
else
result = entry1->size - entry2->size;
}
else if (col2 == 5) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask)
result = entry2->time - entry1->time;
else
result = entry1->time - entry2->time;
}
else if (col2 == 6) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask)
result = (LONG) stricmp(entry2->user, entry1->user);
else
result = (LONG) stricmp(entry1->user, entry2->user);
}
else if (col2 == 7) {
if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask)
result = entry2->link - entry1->link;
else
result = entry1->link - entry2->link;
}
return (result);
}
void resultview_fillstem(struct resultdata *data, char *stem)
{
int i;
song item;
char buf[1024], buf2[32];
struct RexxMsg *m;
u_long tmp;
GetAttr(MUIA_Application_RexxMsg, gui->app, &tmp);
m = (struct RexxMsg *)tmp;
for (i=0; i<data->resultview_count; i++) {
DoMethod(data->list, MUIM_NList_GetEntry, i, &item);
if (item) {
sprintf(buf, "%s.%d.TITLE", stem, i);
SetRexxVar(m, buf, item->title, strlen(item->title));
sprintf(buf, "%s.%d.MD5", stem, i);
SetRexxVar(m, buf, item->md5, strlen(item->md5));
sprintf(buf, "%s.%d.SIZE", stem, i);
sprintf(buf2, "%ld", item->size);
SetRexxVar(m, buf, buf2, strlen(buf2));
sprintf(buf, "%s.%d.BITRATE", stem, i);
sprintf(buf2, "%ld", item->bit);
SetRexxVar(m, buf, buf2, strlen(buf2));
sprintf(buf, "%s.%d.FREQUENCY", stem, i);
sprintf(buf2, "%ld", item->freq);
SetRexxVar(m, buf, buf2, strlen(buf2));
sprintf(buf, "%s.%d.TIME", stem, i);
sprintf(buf2, "%ld", item->time);
SetRexxVar(m, buf, buf2, strlen(buf2));
sprintf(buf, "%s.%d.LINK", stem, i);
sprintf(buf2, "%d", item->link);
SetRexxVar(m, buf, buf2, strlen(buf2));
sprintf(buf, "%s.%d.USER", stem, i);
SetRexxVar(m, buf, item->user, strlen(item->user));
}
else {
gRC = 10;
break;
}
}
sprintf(buf, "%s.COUNT", stem);
sprintf(buf2, "%d", data->resultview_count);
SetRexxVar(m, buf, buf2, strlen(buf2));
}